/**
  ******************************************************************************
  * @file           : rs485n1.h
  * @brief          : Header for main.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __RS485N1_H
#define __RS485N1_H

#include <stdint.h>
#include "core_cm4.h"

#define RS485N1_UART                     UART7
#define RS485N1_UART_BAUDRATE            115200
#define RS485N1_UART_IRQn                UART7_IRQn
#define RS485N1_UART_IRQHandler          UART7_IRQHandler
#define RS485N1_UART_EnableClock()       LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_UART7)
#define RS485N1_UART_IO_EnableClock()    LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOE)

#define RS485N1_OUTTIMER                 TIM14
#define RS485N1_OUTTIMER_IRQn            TIM8_TRG_COM_TIM14_IRQn
#define RS485N1_OUTTIMER_IRQHandler      TIM8_TRG_COM_TIM14_IRQHandler
#define RS485N1_OUTTIMER_EnableClock()   LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM14)

#define RS485N1_GPIO_Port                GPIOE
#define RS485N1_GPIO_LL_AF               LL_GPIO_AF_8
#define RS485N1_TX_LL_Pin                LL_GPIO_PIN_8
#define RS485N1_RX_LL_Pin                LL_GPIO_PIN_7

#define RS485N1_RECV_QUE_LENGTH          5
#define RS485N1_RECV_QUE_ITEMSIZE        sizeof(Rs485n1_RecvBufStru)

#define RS485N1_FRAME_FIXLEN             8u
#define RS485N1_FRAME_BUFLEN             RS485N1_FRAME_FIXLEN + 4

typedef struct
{
  uint8_t cnt;
  uint8_t buf[RS485N1_FRAME_BUFLEN];
}Rs485n1_RecvBufStru;

extern void rs485n1_uart_init(void);
extern void rs485n1_send_str(const char *buf);
extern void rs485n1_send_buf(const uint8_t *buf, uint32_t len);

extern void rs485n1_protc_init(void);
extern void rs485n1_protc_process(void);
extern void rs485n1_protc_rcvisr(__I uint8_t rcvdt);
extern void rs485n1_protc_rcvtimeout(void);

#endif /* __RS485N1_H */
